import java.util.Scanner;

/**
 * <p>
 * 创建日期：2021-07-28 23:43
 *
 * @author Hoppinging
 * @version 1.1
 * @since 1.0
 */
public class Test {
    public static void main(String[] args) {
        CURD curd = new CURD();
        Scanner scanner = new Scanner(System.in);
        System.out.println("1. 打印全部数据\n" +
                "2. 根据ID查询数据\n" +
                "3. 根据名字查询数据\n" +
                "4. 插入数据\n" +
                "5. 删除数据\n" +
                "6. 修改数据\n" +
                "7. 退出\n");
        while(scanner.hasNextInt()){
            switch (scanner.nextInt()){
                case 1 -> curd.print();
                case 2 -> {
                    System.out.println("请输入ID：");
                    curd.retrieve(scanner.nextInt());
                }
                case 3 -> {
                    System.out.println("请输入名字：");
                    scanner.nextLine();
                    curd.retrieve(scanner.next());
                }
                case 4 -> {
                    System.out.println("请输入ID：");
                    int ID = scanner.nextInt();
                    System.out.println("请输入名字：");
                    String name = scanner.next();
                    scanner.nextLine();
                    System.out.println("请输入体重：");
                    double weight = scanner.nextDouble();
                    System.out.println("请输入出生日期（yyyy-mm-dd）：");
                    String date = scanner.next();
                    scanner.nextLine();
                    curd.create(ID, name, weight, date);
                }
                case 5 -> {
                    System.out.println("请输入删除目标ID：");
                    int ID = scanner.nextInt();
                    curd.delete(ID);
                }
                case 6 -> {
                    System.out.println("请输入修改目标ID：");
                    int ID = scanner.nextInt();
                    System.out.println("请输入新ID：");
                    int new_ID = scanner.nextInt();
                    System.out.println("请输入名字：");
                    String name = scanner.next();
                    scanner.nextLine();
                    System.out.println("请输入体重：");
                    double weight = scanner.nextDouble();
                    System.out.println("请输入出生日期（yyyy-mm-dd）：");
                    String date = scanner.next();
                    scanner.nextLine();
                    curd.update(ID, new_ID, name, weight, date);
                }
                case 7 -> {
                    return;
                }
                default -> throw new IllegalStateException("Unexpected value: " + scanner.nextInt());
            }
            System.out.println("1. 打印全部数据\n" +
                    "2. 根据ID查询数据\n" +
                    "3. 根据名字查询数据\n" +
                    "4. 插入数据\n" +
                    "5. 删除数据\n" +
                    "6. 修改数据\n" +
                    "7. 退出\n");
        }
    }
}
